package com.whp.service.impl;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author wanghp
 * @version 1.0   PropertyEditorRegistrySupport.createDefaultEditors() ----------------------------- BeanWrapperImpl
 * @date 2020/8/12 14:53
 * 自定义属性编辑器MessageServiceImpl ，解决xml传入string无法解析为Date问题，然后接下来就是注册自定义编辑器
 */

public class DatePropertyEditor extends PropertyEditorSupport {

	private String format = "yyyy-MM-dd HH:mm:ss";

	public void setFormat(String format) {
		this.format = format;
	}

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		System.out.println("text:" + text);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
		try {
			Date parseDate = simpleDateFormat.parse(text);
			this.setValue(parseDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}

	}
}
